package com.csu.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.csu.common.CommonResponse;
import com.csu.service.HomeworksService;
import com.csu.vo.HomeworkSubjectRespVO;
import com.csu.vo.PostHomeworkReqVO;
import com.csu.vo.SubjectRespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/homeworks")
public class HomeworksController {
    @Autowired
    HomeworksService homeworksService;

    /**
     *按学科查询作业列表
     */
    @GetMapping("/{subjectId}/{userId}/0")
    //@SaCheckRole(value = {"parent", "student"}, mode = SaMode.OR)
    public CommonResponse<List<HomeworkSubjectRespVO>> getHomeworkList(@PathVariable int subjectId, @PathVariable int userId){
        return homeworksService.getHomeworkList(subjectId, userId);
    }

    /**
     * 发布作业
     */
    @PostMapping("")
    //@SaCheckRole("teacher")
    public CommonResponse<Object> postHomework(@RequestBody PostHomeworkReqVO postHomeworkReqVO, @RequestParam int id){
        return homeworksService.postHomework(postHomeworkReqVO.getHomeworkSubjectId(),
                postHomeworkReqVO.getHomeworkName(),postHomeworkReqVO.getHomeworkPath(), id);
    }

    /**
     * 获取作业详情
     */
    @GetMapping("/{homeworkId}/1")
    //@SaCheckRole(value = {"parent", "student", "teacher"}, mode = SaMode.OR)
    public CommonResponse<HomeworkSubjectRespVO> getHomework(@PathVariable int homeworkId){
        return homeworksService.getHomework(homeworkId);
    }

    /**
     * 查询自己发布的作业列表
     */
    @GetMapping("")
    //@SaCheckRole("teacher")
    public CommonResponse<List<HomeworkSubjectRespVO>> getSelfHomework(@RequestParam int id){
        return homeworksService.getSelfHomework(id);
    }

    /**
     * 老师删除作业
     */
    @DeleteMapping("/{homeworkId}")
    //@SaCheckRole("teacher")
    public CommonResponse<Object> deleteHomework(@PathVariable int homeworkId, @RequestParam int id){
        return homeworksService.deleteHomework(homeworkId, id);
    }

    /**
     * 按学科查询作业列表（学生，家长）
     */
    @GetMapping("/{subjectId}/0/{classId}")
    public CommonResponse<List<HomeworkSubjectRespVO>> getHomeworkListStudent(@PathVariable int subjectId, @PathVariable int classId){
        return homeworksService.getHomeworkListStudent(subjectId, classId);
    }

    /**
     * 获取作业学科列表
     */
    @GetMapping("/subjects/{classId}")
    public CommonResponse<List<SubjectRespVO>> getSubjects(@PathVariable int classId){
        return homeworksService.getSubjects(classId);
    }
}
